﻿using FriendStar.Code;
using FriendStar.Domain.Entity.VBaseData;
using FriendStar.Domain.IRepository.VBaseData;
using FriendStar.Repository.VBaseData;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;

namespace FriendStar.Application.VBaseData
{
    public class V_CPK_45_HZ_StoCPKListAcco_MidApp
    {
        private IV_CPK_45_HZ_StoCPKListAcco_MidRepository service = new V_CPK_45_HZ_StoCPKListAcco_MidRepository();

        public List<V_CPK_45_HZ_StoCPKListAcco_MidEntity> GetList()
        {
            return service.IQueryable().ToList();
        }

        public List<V_CPK_45_HZ_StoCPKListAcco_MidEntity> GetList(string fdocuno)
        {
            var expression = ExtLinq.True<V_CPK_45_HZ_StoCPKListAcco_MidEntity>();
            if(string.IsNullOrEmpty(fdocuno))
            {
                fdocuno = "";
            }
            expression= expression.And(p => p.FDocuNO == fdocuno);
            return service.FindList(expression).ToList();
        }
        public List<V_CPK_45_HZ_StoCPKListAcco_MidEntity> StoInCPKMidList(Pagination pagination, string companyno, string productionno, string fcurdate, string fvoucherno, string faccountDate, string fdocuno,string type)
        {
            var expression = ExtLinq.True<V_CPK_45_HZ_StoCPKListAcco_MidEntity>();
            if (!string.IsNullOrEmpty(companyno))
            {
                expression = expression.And(t => t.FProCompanyNO.Contains(companyno));
            }
            if (!string.IsNullOrEmpty(productionno))
            {
                expression = expression.And(t => t.FProductionNO.Contains(productionno));
            }
            if (!string.IsNullOrEmpty(fcurdate))
            {
                expression = expression.And(t => t.FCurDate.Contains(fcurdate));
            }
            if (!string.IsNullOrEmpty(fvoucherno))
            {
                expression = expression.And(t => t.FCredence.Contains(fvoucherno));
            }
            if (!string.IsNullOrEmpty(faccountDate))
            {
                expression = expression.And(t => t.FAccountDate.Contains(faccountDate));
            }
            if(!string.IsNullOrEmpty(fdocuno))
            {
                expression = expression.And(t => t.FDocuNO.Contains(fdocuno));
            }
            if (!string.IsNullOrEmpty(type))
            {
                expression = expression.And(t => t.FDocuTypeNO == type);
            }
            else
            {
                expression = expression.And(t => t.FDocuTypeNO == "CR"||t.FDocuTypeNO=="CW");
            }
            return service.FindList(expression, pagination).OrderBy(t => t.UseUnit).ToList();
        }
        public List<V_CPK_45_HZ_StoCPKListAcco_MidEntity> GetOutParameterGridJson(Pagination pagination, string companyname, string productionno, string fcurdate, string fvoucherno, string ledgerdate)
        {
            var expression = ExtLinq.True<V_CPK_45_HZ_StoCPKListAcco_MidEntity>();
            if (!string.IsNullOrEmpty(companyname))
            {
                expression = expression.And(t => t.FProCompanyName.Contains(companyname));
            }
            if (!string.IsNullOrEmpty(productionno))
            {
                expression = expression.And(t => t.FProductionNO.Contains(productionno));
            }
            if (!string.IsNullOrEmpty(fcurdate))
            {
                expression = expression.And(t => t.FCurDate.Contains(fcurdate));
            }
            if (!string.IsNullOrEmpty(fvoucherno))
            {
                expression = expression.And(t => t.FCredence.Contains(fvoucherno));
            }
            if (!string.IsNullOrEmpty(ledgerdate))
            {
                expression = expression.And(t => t.FAccountDate.Contains(ledgerdate));
            }
            expression = expression.And(t => t.FDocuTypeNO==("CC"));
            return service.FindList(expression, pagination).OrderBy(t => t.UseUnit).ToList();
        }
    }
}
